﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>支票列表</title>
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="../Scripts/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../Scripts/themes/icon.css">
    <script type="text/javascript">
        var listGrid, colData, searchPanel, searchSql = '', defaultSort, defaultWhere, currentUID, currentGIndex = -1, genRenderCheckbox, genRenderDateformat, genRenderDateformatSS;
        var showSearchPanel, showToolBar, oldRowData,  goOn = true, ifh;
        var actionRoot = "../handler/ajax.ashx?type=AjaxSystem", comboxStatusData = [];
                                                                  
        $(document).ready(function () {
            $.ajax({
                cache: false, async: false,
                url: '../handler/ajax.ashx?type=AjaxSystem&method=loginIn',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载用户信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    if (data.IsError) {
                        goOn = false;
                        $.omMessageBox.alert({
                            content: '发现错误<BR>：' + data.Message,
                            onClose: function () {
                                window.top.location.href = decodeURIComponent("../Index.aspx");
                            }
                        });
                    }
                    else {
                        goOn = true;
                        currentUID = data.Data.userid
                    }
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.alert({
                        content: '发现错误<BR>：' + result.status,
                        onClose: function () {
                            window.top.location.href = decodeURIComponent("Index.aspx");
                        }
                    });
                }
            });
            var element = $('body').omBorderLayout({
                fit: true,
                spacing: 0,
                panels: [
                {
                    id: "center-panel",
                    header: true,
                    title: '<span style="color:#15428B;font-weight: bold;padding:6px;">支票列表</span><span id="button-delete" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/delete.png" width="16" height="16" style="border:none;vertical-align:middle" />删除</span><span id="button-copy" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/copy.png" width="16" height="16" style="border:none;vertical-align:middle" />复制</span><span id="button-edit" style="float:right;text-align:center;cursor:pointer;"><img src="../Content/Images/List/edit.png" width="16" height="16" style="border:none;vertical-align:middle" />编辑</span><span id="button-new" style="float:right;text-align:center;cursor:pointer;display:none;"><img src="../Content/Images/List/add.png" width="16" height="16" style="border:none;vertical-align:middle" />新增</span>',
                    region: "center"
                }, {
                    id: "west-panel",
                    resizable: true,
                    collapsible: true,
                    title: "<span style='color:#15428B;font-weight: bold;padding:6px;'>查询条件</span>",
                    region: "west",
                    width: 230
                },
                {
                    id: "south-panel",
                    region: "south",
                    header: false,
                    resizable: false,
                    collapsible: false,
                    height: 50
                }
                ]
            });
            showSearchPanel();
            showToolBar();
            colData = [
                { header: '支票号码', name: 'CheckNo', width: 80, align: 'center' },
                { header: '购买时间', name: 'PurchaseDate', width: 80, align: 'center', renderer: genRenderDateformatSS },
                { header: '支票状态', name: 'CheckStatusName', width: 60, align: 'center' },
                { header: '支票额度', name: 'CheckTypeName', width: 60, align: 'center' },
                { header: '支票部门', name: 'DeptName', width: 60, align: 'center' },
                { header: '支票金额', name: 'Amount', width: 60, align: 'center' },
                { header: '备注', name: 'Note', width: 80, align: 'center' },
                { header: '创建人', name: 'UserCreate', width: 80, align: 'center' },
                { header: '创建时间', name: 'CreateDate', width: 200, align: 'center', renderer: genRenderDateformat },
                { header: '修改人', name: 'UserModify', width: 80, align: 'center' },
                { header: '修改时间', name: 'ModifyDate', width: 120, align: 'center', renderer: genRenderDateformat }
            ];
            defaultSort = { sortby: 'CheckNo', sortdir: 'ASC' };
            defaultWhere = { where: ' 1=1 ' };
            listGrid = $('#listgrid').omGrid({
                width: '100%',
                height: 'fit',
                onRowDblClick: function (rowIndex, rowData, event) {
                    art.dialog.data('currentUID', currentUID);
                    art.dialog.data('Index', rowIndex);
                    art.dialog.data('RowData', rowData);
                    art.dialog.data('Mode', 'update');
                    art.dialog.data('NewRowData', undefined);
                    art.dialog.open('../CheckPages/CheckRegister.aspx', {
                        id: 'CheckRegisterUpdate', width: 700, height: 320, title: '支票登记', lock: true,
                        close: function () {
                        }
                    }, false);
                },
                onRowClick: function (rowIndex, rowData, event) {
                },
                editMode: "insert",
                singleSelect: true,
                limit: 100,
                extraData: $.extend(defaultWhere, defaultSort),
                dataSource: "{rows:[],total:0}",
                colModel: colData
            });
        });

        genRenderDateformatSS = function (colValue, rowData, rowIndex) {
            if (colValue.length == 0 || colValue == null) {
                return '';
            }
            else {
                if (colValue.indexOf("/Date") > -1)
                    return new Date(parseInt(colValue.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd");
                else
                    return colValue;
            }
        }

        genRenderDateformat = function (colValue, rowData, rowIndex) {
            if (colValue.length == 0 || colValue == null) {
                return '';
            }
            else {
                if (colValue.indexOf("/Date") > -1)
                    return new Date(parseInt(colValue.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd hh:mm");
                else
                    return colValue;
            }
        }

        showToolBar = function () {
            $('span#button-new').click(function () {
                art.dialog.data('currentUID', currentUID);
                art.dialog.data('Index', 0);
                art.dialog.data('RowData', []);
                art.dialog.data('Mode', 'new');
                art.dialog.data('NewRowData', undefined);
                art.dialog.open('../CheckPages/CheckRegister.aspx', {
                    id: 'CheckRegisterAdd', width: 700, height: 320, title: '支票登记', lock: true,
                    close: function () {
                    }
                }, false);
            });
            $('span#button-copy').click(function () {
                if (listGrid[0].rows.length > 0) {
                    var selectRow = listGrid.omGrid("getSelections", true);
                    var selectRowIndex = listGrid.omGrid("getSelections");
                    if (selectRow.length == 1 && selectRowIndex.length == 1) {
                        art.dialog.data('currentUID', currentUID);
                        art.dialog.data('Index', selectRowIndex[0]);
                        art.dialog.data('RowData', selectRow[0]);
                        art.dialog.data('Mode', 'copy');
                        art.dialog.data('NewRowData', undefined);
                        art.dialog.open('../CheckPages/CheckRegister.aspx', {
                            id: 'CheckRegisterCopy', width: 700, height: 320, title: '支票登记', lock: true,
                            close: function () {
                            }
                        }, false);
                    }
                    else {
                        $.omMessageBox.alert({
                            content: '至少选取一条可复制的数据'
                        });
                    }
                }
                else {
                    $.omMessageBox.alert({
                        content: '没有可复制的数据'
                    });
                }
            });
            $('span#button-edit').click(function () {
                if (listGrid[0].rows.length > 0) {
                    var selectRow = listGrid.omGrid("getSelections", true);
                    var selectRowIndex = listGrid.omGrid("getSelections");
                    if (selectRow.length == 1 && selectRowIndex.length == 1) {
                        art.dialog.data('currentUID', currentUID);
                        art.dialog.data('Index', selectRowIndex[0]);
                        art.dialog.data('RowData', selectRow[0]);
                        art.dialog.data('Mode', 'update');
                        art.dialog.open('../CheckPages/CheckRegister.aspx', {
                            id: 'CheckRegisterUpdate', width: 700, height: 320, title: '支票登记', lock: true,
                            close: function () {
                            }
                        }, true);
                    }
                    else {
                        $.omMessageBox.alert({
                            content: '至少选取一条可编辑的数据'
                        });
                    }
                }
                else {
                    $.omMessageBox.alert({
                        content: '没有可编辑的数据'
                    });
                }
            });
            $('span#button-delete').click(function () {
                if (listGrid[0].rows.length > 0) {
                    var selectRow = listGrid.omGrid("getSelections", true);
                    var selectRowIndex = listGrid.omGrid("getSelections");
                    if (selectRow.length == 1 && selectRowIndex.length == 1) {
                        $.omMessageBox.confirm({
                            title: '确认删除',
                            content: '确定要删除吗？',
                            onClose: function (v) {
                                if (v) {
                                    $.ajax({
                                        cache: false, async: false,
                                        url: '../handler/ajax.ashx?type=AjaxSystem&method=RemoveCheck',
                                        dataType: 'json', type: 'post',
                                        data: { UID: selectRow[0].UID, USERID: currentUID },
                                        beforeSend: function () {
                                            $.omMessageBox.waiting({
                                                title: '请等待',
                                                content: '系统正在删除信息,请稍后...'
                                            });
                                        },
                                        complete: function () {
                                            $.omMessageBox.waiting("close");
                                        },
                                        success: function (data) {
                                            if (data.IsError) {
                                                $.omMessageBox.alert({
                                                    content: '错误：' + data.Message
                                                });
                                            }
                                            else {
                                                $.omMessageBox.alert({
                                                    content: data.Message,
                                                    onClose: function () {
                                                        listGrid.omGrid("deleteRow", selectRowIndex[0]);
                                                        listGrid.omGrid('saveChanges');
                                                        listGrid.omGrid("refresh");
                                                    }
                                                });
                                            }
                                        },
                                        error: function (result) {
                                            $.omMessageBox.alert({
                                                content: '发现错误<BR>：' + result.status
                                            });
                                        }
                                    });
                                }
                            }
                        });
                    }
                    else {
                        $.omMessageBox.alert({
                            content: '至少选取一条可删除的数据'
                        });
                    }
                }
            });
        }

        showSearchPanel = function () {
            $.ajax({
                cache: false, async: false,
                url: "../Handler/combox.ashx?view=vBaseData",
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载基础信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    comboxStatusData = []
                    $.each(data, function (index, value) {
                        switch (value.Type) {
                            case '支票状态':
                                comboxStatusData.push({ name: value.Name, code: value.Code, type: value.Type });
                                return true;
                            default:
                                return true;
                        }
                    })
                    $('#CheckStatusName').combobox({
                        data: comboxStatusData,
                        valueField: 'name',
                        textField: 'name',
                    });
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.waiting("close");
                    $.omMessageBox.alert({
                        content: '发现错误<BR>：' + result.status
                    });
                }
            });
            $("#button-search").click(function () {
                var custWhere = '';
                if ($("#search-panel input[id='PurchaseDateStart']").datebox("getValue").length > 0) {
                    custWhere = " AND (PurchaseDate BETWEEN '" + $("#search-panel input[id='PurchaseDateStart']").datebox("getValue") + "' AND ";
                    if ($("#search-panel input[id='PurchaseDateEnd']").datebox("getValue").length > 0) {
                        custWhere += " '" + $("#search-panel input[id='PurchaseDateEnd']").datebox("getValue") + "') "
                    }
                    else {
                        custWhere += " GETDATE()) "
                    }
                }
                if ($("#search-panel input[id='CheckStatusName']").combobox("getValue").length > 0) {
                    custWhere += ' AND CheckStatusName LIKE ' + '\'%' + $("#search-panel input[id='CheckStatusName']").combobox("getValue") + '%\'';
                }
                if ($("#search-panel input[id='CheckNo']").val().length > 0) {
                    custWhere += ' AND CheckNo LIKE ' + '\'%' + $("#search-panel input[id='CheckNo']").val() + '%\'';
                }
                if ($("#search-panel input[id='DeptName']").val().length > 0) {
                    custWhere += ' AND DeptName LIKE ' + '\'%' + $("#search-panel input[id='DeptName']").val() + '%\'';
                }
                searchSql = 'SELECT * FROM vCheck WHERE ' + defaultWhere.where + custWhere;
                listGrid.omGrid({
                    extraData: $.extend({ where: defaultWhere.where + custWhere }, defaultSort),
                    dataSource: '../Handler/grid.ashx?view=vCheck'
                });
            });
            $('#button-clear').click(function () {
                $("div[id='search-panel'] input").val("");
            });
            $('#button-load').click(function () {
                art.dialog.open('../CheckPages/CheckBatchAdd.aspx', {
                    id: 'CheckBatchAdd', width: 400, height: 350, title: '加载支票', lock: true,
                    close: function () {
                    }
                }, false);
            });
            $('#button-export').click(function () {
                if (searchSql != '')
                    window.open('../handler/gridexport.ashx?datasql=' + searchSql + '&sheetname=发票导出' + '&filename=发票导出.xls');
            });
        };
    </script>
</head>
<body>
        <div id="west-panel" class="westpanel">
            <div id="search-panel">
                <table style="vertical-align:top;">
                    <tr>
                        <td style="width: 80px" align="right">
                            <span class="label">购买时间</span>
                        </td>
                        <td>
                            <input type="text" class="easyui-datebox" id="PurchaseDateStart" style="width: 120px;" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 80px" align="right">
                            <span class="label">到</span>
                        </td>
                        <td>
                            <input type="text" class="easyui-datebox" id="PurchaseDateEnd" style="width: 120px;" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 80px" align="right">
                            <span class="label">支票状态</span>
                        </td>
                        <td>
                            <input  class="easyui-combobox" name="CheckStatusName" id="CheckStatusName" style="width: 120px;" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 80px" align="right">
                            <span class="label">支票号码</span>
                        </td>
                        <td>
                            <input type="text" class="input-text" id="CheckNo" 
                             data-options="required:false;validType:'length[1,8]'" style="border: 1px solid #A4BED4; height:20px;width: 120px;" />
                       </td>
                    </tr>
                    <tr>
                        <td style="width: 60px" align="right">
                            <span class="label">所属部门</span>
                        </td>
                        <td>
                            <input type="text" class="input-text" name="DeptName" id="DeptName" 
                                data-options="required:false;" style="border: 1px solid #A4BED4; height:20px;width: 118px;" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="center-panel">
            <table id="listgrid"></table>
        </div>
        <div id="south-panel">
            <table style="margin-top: 5px; margin-left: 20px;">
                <tr>
                    <td>
                        <input id="button-search" type="button" class="btnCss" value="搜    索" />
                        <input id="button-clear" type="button" class="btnCss" value="清    空" style="margin-left: 20px;" />
                        <input id="button-export" type="button" class="btnCss" value="导    出" style="margin-left: 20px;" />
                        <input id="button-load" type="button" class="btnCss" value="加    载" style="margin-left: 20px;" />
                        <input id="button-valid" type="button" class="btnCss" value="作    废" style="margin-left: 20px;" />
                    </td>
                </tr>
            </table>
        </div>
</body>
</html>
